<?php
class AyudantesController extends AppController {

	var $name = 'Ayudantes';


	function add() {
		if (!empty($this->data)) {
			$this->Ayudante->create();
			if ($this->Ayudante->save($this->data)) {
				$this->Session->setFlash(__('The ayudante has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ayudante could not be saved. Please, try again.', true));
			}
		}
		$comunas = $this->Ayudante->Comuna->find('list');
		$asignaturas = $this->Ayudante->Asignatura->find('list');
		$modulos = $this->Ayudante->Modulo->find('list', array('fields'=>array('Modulo.inicio', 'Modulo.termino')));
		print_r($modulos);
                $this->set(compact('comunas', 'asignaturas', 'modulos'));
	}


	function admin_index() {
		$this->Ayudante->recursive = 0;
		$this->set('ayudantes', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ayudante', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('ayudante', $this->Ayudante->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Ayudante->create();
			if ($this->Ayudante->save($this->data)) {
				$this->Session->setFlash(__('The ayudante has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ayudante could not be saved. Please, try again.', true));
			}
		}
		$comunas = $this->Ayudante->Comuna->find('list');
		$asignaturas = $this->Ayudante->Asignatura->find('list');
		$modulos = $this->Ayudante->Modulo->find('list');
		$this->set(compact('comunas', 'asignaturas', 'modulos'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ayudante', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Ayudante->save($this->data)) {
				$this->Session->setFlash(__('The ayudante has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ayudante could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Ayudante->read(null, $id);
		}
		$comunas = $this->Ayudante->Comuna->find('list');
		$asignaturas = $this->Ayudante->Asignatura->find('list');
		$modulos = $this->Ayudante->Modulo->find('list');
		$this->set(compact('comunas', 'asignaturas', 'modulos'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ayudante', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Ayudante->delete($id)) {
			$this->Session->setFlash(__('Ayudante deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Ayudante was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>